﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace JumpingBalls.AppCode
{
    public class BallBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int ballValue;

            int.TryParse(value.ToString(), out ballValue);

            return Application.Current.Resources[string.Format("BallBrush{0}", ballValue)];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ScoreConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int score = int.Parse(value.ToString());
            return score.ToString("D7");
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class RankConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int showtime = (int)value;
            return showtime.ToString("D2");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class TopsScoreConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int score = (int)value;

            if (score == int.MinValue)
            {
                return "---";
            }

            return score;
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime dateTime = (DateTime)value;

            if (dateTime == DateTime.MaxValue)
            {
                return "---";
            }

            return dateTime.ToString("yyyy-MM-dd");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
